package server;

import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.sql.SQLException;

public class MasterServer {

	public static void main(String[] args) throws IOException, SQLException {
		InetAddress myself = InetAddress.getLocalHost();
		System.out.println("Myname:" + myself.getHostName());
		System.out.println("MyIP:" + myself.getHostAddress());
		ServerSocket serverSocket = new ServerSocket(1235);
		System.out.println("MasterServer avviato");
		try {
			while (true) {
				Socket clientSocket = serverSocket.accept();
				System.out.println("Connessione accettata " + clientSocket);
				try {
					new ServerThread(clientSocket);
				} catch (IOException e) {
					clientSocket.close();
				}
			}
		} catch (IOException e) {
			System.err.println("Accept failed");
			System.exit(1);
		}
		System.out
				.println("Chiusura MasterServer...\nNon e' piu' possibile effetuare azioni.");
		serverSocket.close();
	}
}
